package com.example.wangzh.mytest;

import static android.content.res.Configuration.UI_MODE_NIGHT_MASK;
import static android.content.res.Configuration.UI_MODE_NIGHT_NO;
import static android.content.res.Configuration.UI_MODE_NIGHT_UNDEFINED;
import static android.content.res.Configuration.UI_MODE_NIGHT_YES;
import static android.content.res.Configuration.UI_MODE_TYPE_APPLIANCE;
import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
import static android.content.res.Configuration.UI_MODE_TYPE_DESK;
import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
import static android.content.res.Configuration.UI_MODE_TYPE_NORMAL;
import static android.content.res.Configuration.UI_MODE_TYPE_TELEVISION;
import static android.content.res.Configuration.UI_MODE_TYPE_UNDEFINED;
import static android.content.res.Configuration.UI_MODE_TYPE_WATCH;

import android.app.UiModeManager;
import android.content.Context;
import android.content.res.Configuration;
import android.view.View;
import android.widget.Toast;

import com.example.wangzh.mytest.base.BaseActivity;
import com.example.wangzh.mytest.constant.LogTag;
import com.example.wangzh.mytest.databinding.ActivityBigScreenAdaptBinding;
import com.example.wangzh.mytest.utils.LogUtils;

@SuppressWarnings("Convert2Lambda")
public class BigScreenAdaptActivity extends BaseActivity<ActivityBigScreenAdaptBinding> {
    public static final String TAG = BigScreenAdaptActivity.class.toString();

    @Override
    protected void initView() {
        mBinding.btnCheckUiMode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                checkUiMode();
            }
        });
    }

    private void checkUiMode() {
        UiModeManager uiModeManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
        int uiMode = uiModeManager.getCurrentModeType();
        StringBuilder sb = new StringBuilder();
        // Configuration.java
        switch ((uiMode & UI_MODE_TYPE_MASK)) { //UI_MODE_TYPE_MASK = 0000 1111
            case UI_MODE_TYPE_UNDEFINED://UI_MODE_TYPE_UNDEFINED = 0000 0000
                sb.append("?ui mode");
                break;
            case UI_MODE_TYPE_NORMAL://UI_MODE_TYPE_UNDEFINED = 0000 0001
                sb.append("normal");
                break;
            case UI_MODE_TYPE_DESK://UI_MODE_TYPE_DESK = 0000 0010
                sb.append("desk");
                break;
            case UI_MODE_TYPE_CAR://UI_MODE_TYPE_CAR = 0000 0011
                sb.append("car");
                break;
            case UI_MODE_TYPE_TELEVISION://UI_MODE_TYPE_TELEVISION = 0000 0100
                sb.append("television");
                break;
            case UI_MODE_TYPE_APPLIANCE://UI_MODE_TYPE_APPLIANCE =0000 0101
                sb.append("appliance");
                break;
            case UI_MODE_TYPE_WATCH://UI_MODE_TYPE_WATCH = 0000 0110
                sb.append("watch");
                break;
            default:
                sb.append("ui mode=");
                sb.append(uiMode & UI_MODE_TYPE_MASK);
                break;
        }
        switch ((uiMode & UI_MODE_NIGHT_MASK)) {//UI_MODE_NIGHT_MASK = 0011 0000
            case UI_MODE_NIGHT_UNDEFINED://UI_MODE_NIGHT_UNDEFINED = 0000 0000
                sb.append(" ?night");
                break;
            case UI_MODE_NIGHT_NO://UI_MODE_NIGHT_NO = 0001 0000
                sb.append(" night no");
                break;
            case UI_MODE_NIGHT_YES://UI_MODE_NIGHT_YES = 0010 0000
                sb.append(" night");
                break;
            default:
                sb.append(" night=");
                sb.append(uiMode & UI_MODE_NIGHT_MASK);
                break;
        }
        LogUtils.i(TAG, sb.toString());
        Toast.makeText(this, sb.toString(), Toast.LENGTH_SHORT).show();
    }
}
